Excel BI - Excel Challenge 734

excel-challenges
excel-formulas
🔰 Populate the given number spiral.
Published

March 24, 2026

Illustration for Excel BI - Excel Challenge 734

Challenge Description

🔰 Populate the given number spiral.

Solutions

library(tidyverse)
library(readxl)

path = "Excel/700-799/734/734 Number Spiral Grid.xlsx"
test = read_excel(path, range = "A2:H9", col_names = FALSE) %>% as.matrix()

generate_tidy_snake <- function(n = 8) {
  expand.grid(r = 1:n, c = 1:n) %>%
    mutate(value = ifelse(r >= c,
                          ifelse(r %% 2, (r - 1)^2 + c, r^2 - c + 1),
                          ifelse(c %% 2, c^2 - r + 1, (c - 1)^2 + r))) %>%
    pivot_wider(names_from = c, values_from = value) %>%
    select(-r) %>%
    as.matrix()
}

result = generate_tidy_snake(8)

all.equal(test, result, check.attributes = FALSE)
# [1] TRUE
  • Logic: Read the workbook ranges needed for the challenge; Derive the required intermediate columns; Reshape the result into the workbook output format; Apply the business rule conditions explicitly.
  • Strengths: The reshaping step mirrors the workbook output closely instead of forcing extra post-processing.
  • Areas for Improvement: The solution assumes the workbook layout and selected ranges remain stable, so any structural change in the sheet would require small adjustments.
  • Gem: The last reshape turns a raw transformation into something that already looks like a report.
import pandas as pd
import numpy as np

path = "700-799/734/734 Number Spiral Grid.xlsx"
test = pd.read_excel(path, header=None, skiprows=1, nrows=8, usecols="A:H").to_numpy()

def generate_tidy_snake(n=8):
    r, c = np.indices((n, n)) + 1
    return np.where(
        r >= c,
        np.where(r % 2, (r - 1) ** 2 + c, r ** 2 - c + 1),
        np.where(c % 2, c ** 2 - r + 1, (c - 1) ** 2 + r)
    )

result = generate_tidy_snake(8)

print(np.array_equal(test, result))

The Python version mirrors the same workbook logic with a concise, direct implementation.

Difficulty Level

Medium

The individual steps are manageable, but the correct transformation pattern is not obvious from the raw data.